Get Data Source Server Roles
{ getRolesByServer }
Returns all roles IDs and its settings for a server.
Method
/API2/dataSources/getRolesByServer
Input Parameters
Name
serverId
Type
string
Description
The server's system ID
Output Response
Successful Result Code
200
Response List Type
Description of Response Type
Object with role and role access types. Note that the response is returned as a list of items of this object type.
Examples
Data Source Operations (JavaScript):
This example demonstrates how to operate with data sources.
The example uses API authentication driven from JavaScript. See Authentication APIs for alternatives.
// URL of the Pyramid installation and the path to the API 2.0 REST methods
var pyramidURL = "http://mysite.com/api2/";
// step 1: authenticate admin account and get token
// NOTE: callApi method is a generic REST method shown below.
let token = callApi("auth/authenticateUser",{
"data":{
"userName":"adminUser",
"password":"12345678"
}
},false);
log("got token "+token);
// step 2: find roles in the system
let findRole = callApi("access/getRolesByName",{
"data": {
"searchValue": "role1",
"searchMatchType": 2//SearchMatchType.Equals
},
"auth": token // admin token generated above
});
let roleId=findRole.data[0].roleId;
log("found role with id= "+ roleId);
// step 3: add a new data source server (IMDB)
let createDataServer = callApi("dataSources/createDataServer",{
"serverData": {
"serverName": "new server",
"serverType":13,// use the server type enumeration. 13 = IMDB
"serverIp": "172.29.3.178",
"port":5060,
"serverAuthenticationMethod":0,//ServerAuthenticationMethod.UserPassword
"userName":"default",
"password":"password",
},
"auth": token // admin token generated above
});
let dataServerId=createDataServer.data.modifiedList[0].id;
log("created dataserver= "+ dataServerId);
// step 4: secure server from step 3 with roles
let addRolesToServer = callApi("dataSources/addRolesToServer",{
"itemRoles": {
"itemId":dataServerId,
"itemRolePairList":[{
"roleId":roleId,
"accessType":2//AccessType.Read
}]
},
"auth": token
});
log("added role1 to the newly created server");
// step 5: optional: check the roels on the server
let getRolesByServer= callApi("dataSources/getRolesByServer",{
"serverId": dataServerId,
"auth": token
});
// step 6: recognize an existing database on the server
//use this method when you want to address the database in Pyramid
let recognizeDataBase = callApi("dataSources/recognizeDataBase",{
"dataBaseRecognitionObject": {
"serverId":dataServerId, //this comes from step 3 above
"dbName":"PyramidDemo"
},
"auth": token
});
let databaseId=recognizeDataBase.data.modifiedList[0].id;
log("found database "+databaseId+" at the dataserver");
// step 7: secure the database from step 3 with roles
let addRolesToDataBase = callApi("dataSources/addRolesToDataBase",{
"itemRoles": {
"itemId":databaseId,
"itemRolePairList":[{
"roleId":roleId,
"accessType":3//AccessType.Write
}]
},
"auth": token
});
// step 8A: read in an existing data model from a PIE file
let file="http://myOtherSite.com/SampleModel.pie";
let modelData=readPieFile(file);
// step 8B: import the file content into Pyramid
let importModel = callApi("dataSources/importModel",{
"modelApiObject": {
"fileZippedData":modelData, //model data from step 8A
"databaseId":databaseId, //from step 6
"materializedRoleAssignmentType":3//MaterializedRoleAssignmentType.ForceParentRoles
},
"auth": token
}).data;
// step 9: secure the model from step 3 with roles
let addRolesToModel = callApi("dataSources/addRolesToModel",{
"itemRoles": {
"itemId":importModel.modelId, //from step 8B
"itemRolePairList":[{
"roleId":roleId,
"accessType":3//AccessType.Write
}]
},
"auth": token
});
//step 10: delete the model
let deleteMaterializedModel = callApi("dataSources/deleteMaterializedModel",{
"modelId": importModel.modelId,
"auth": token
});
//step 11: delete the database
let deleteDataBase=callApi("dataSources/deleteDataBase",{
"databaseId": databaseId,
"auth": token
});
//step 12: delete the dta source (server)
let deleteDataSource = callApi("dataSources/deleteDataSource",{
"sourceId": dataServerId,
"auth": token
});
function log(msg){
document.write(msg);
console.log(msg);
}
function callApi(path,data,parseResult=true){
var xhttp = new XMLHttpRequest();
xhttp.open("POST", pyramidURL+path, false);
xhttp.send(JSON.stringify(data));
if(parseResult){
return JSON.parse(xhttp.responseText);
}else{
return xhttp.responseText;
}
}
//example function to read in the contents of a 'PIE' file that contains
//exported Pyramid content.
function readPieFile(file){
var rawFile = new XMLHttpRequest();
rawFile.open("GET", file, false);
rawFile.send(null);
rawFile.onreadystatechange = function () {
if (request.readyState === 4 && request.status === 200) {
return request.responseText;
}
}
}